import { DataBase } from './database.js'
import { Person } from './person.js'

console.log('当前通讯录数据：', DataBase.read())

const zhangsan = new Person('张三', '翻斗花园001号', '001')
const lisi = new Person('李四', '翻斗花园002号', '002')
const wangwu = new Person('王五', '翻斗花园003号', '003')

DataBase.write([zhangsan, lisi, wangwu])
console.log('增加', zhangsan, lisi, wangwu)

console.log('当前通讯录数据：', DataBase.read())
console.log(
  '查询id为1的：',
  DataBase.read().find((item) => item.id === 1)
)

DataBase.write([zhangsan, { ...lisi, name: '李四狗' }, wangwu])
console.log('更新lisi')
console.log('当前通讯录数据：', DataBase.read())

DataBase.write(DataBase.read().filter((item) => item.id !== 1))
console.log('删除id为1的')
console.log('当前通讯录数据：', DataBase.read())
